<template>
  <el-dialog :title="!dataForm.id ? '审核' : '审核'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="审核" prop="name">
        <el-radio v-model="is_pass" :label="1">审核通过</el-radio>
        <el-radio v-model="is_pass" :label="2">审核不通过</el-radio>
      </el-form-item>
      <el-form-item v-if="is_pass==2" label="理由" prop="type">
        <el-select v-model="value" placeholder="请选择">
          <el-option v-for="item in options" :key="item.value" :label="item.name" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="is_pass==2 && value==2" label="其他" prop="type">
        <el-input type="textarea" v-model="itemMsg" :show-word-limit="true" maxlength="50" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { treeDataTranslate } from '@/utils'
import seviceApi from '@/api/serviceApi.js'
export default {
  data () {
    return {
      visible: false,
      is_pass: 0,
      itemMsg: '',
      dataForm: {
        id: '0',
        audit_status: 0,
        audit_remark: ''
      },
      auditStatus: 0,
      value: 0,
      options: [
        {
          name: '图片内容不符合',
          value: 0
        }, {
          name: '直播时间过长',
          value: 1
        }, {
          name: '其它',
          value: 2
        }
      ],
      dataRule: {
        type: [
          { required: true, message: '菜单名称不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '菜单名称不能为空', trigger: 'blur' }
        ]
      }
    }
  },

  methods: {
    init (id, auditStatus) {
      this.dataForm.id = id || 0
      this.visible = true
      this.dataForm.audit_status = auditStatus
      if (auditStatus != 0) {
        seviceApi.getCelebrityDetail(id).then(res => {
          console.log(res)
          if (res && res.data.code == 200) {

          }
        })
      } else {
        this.dataForm = {
          id: id,
          audit_status: 0,
          audit_remark: ''
        }
      }
      // this.$nextTick(() => {
      //   this.$refs['dataForm'].resetFields()
      // })
    },

    // 提交表单
    dataFormSubmit () {
      if (this.is_pass == 1) {
        let param = {
          id: this.dataForm.id,
          state: 1,
          audit_remark: this.dataForm.audit_remark
        }
        seviceApi.getCelebrityAudit(param).then(res => {
          console.log(res)
          if (res && res.data.code == 200) {
            this.$message({
              showClose: true,
              message: '操作成功',
              type: 'success'
            })
            this.visible = false
            this.$emit('updataList', 1)
          }
        })
      }
      if (this.is_pass == 2) {
        if (this.value == 0) {
          let param = {
            id: this.dataForm.id,
            state: this.is_pass,
            reason: this.options[0].name
          }
          seviceApi.getCelebrityAudit(param).then(res => {
            if (res && res.data.code == 200) {
              this.$message({
                showClose: true,
                message: '操作成功',
                type: 'success'
              })
              this.visible = false
              this.$emit('updataList', 1)
            }
          })
          console.log(param)
        } else if (this.value == 1) {
          let param = {
            id: this.dataForm.id,
            state: this.is_pass,
            reason: this.options[1].name
          }
          seviceApi.getCelebrityAudit(param).then(res => {
            if (res && res.data.code == 200) {
              this.$message({
                showClose: true,
                message: '操作成功',
                type: 'success'
              })
              this.visible = false
              this.$emit('updataList', 1)
            }
          })
          console.log(param)
        } else if (this.value == 2) {
          let param = {
            id: this.dataForm.id,
            state: this.is_pass,
            reason: this.itemMsg
          }
          // if(param.remarks==''){
          //   this.$message({
          //     showClose:true,
          //     message:"请填写拒绝类容"
          //   })
          // }else{
          console.log(param)
          seviceApi.getCelebrityAudit(param).then(res => {
            if (res && res.data.code == 200) {
              this.$message({
                showClose: true,
                message: '操作成功',
                type: 'success'
              })
              this.visible = false
              this.$emit('updataList', 1)
            }
          })
          // }
        }
      }
      // console.log(this.is_pass)
      // console.log(this.dataForm.id)
      // console.log(this.value)
      // console.log(this.itemMsg)

      // var param={
      //   id:this.dataForm.id,
      //   state:this.is_pass,

      // }
    }
  }
}
</script>

<style lang="scss">
</style>
